package com.example.playbox.utils

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper

class MyDBHelper(context: Context) : SQLiteOpenHelper(context, NAME, null, DB_VERSION) {
    companion object {
        const val NAME = "db_game3.db"
        const val DB_VERSION = 2
        const val CREATE_USERDATA1 = "create table tb_Games(gameId char(10) primary key, gameName varchar(20), gameTime varchar(20), gameNote varchar(20), userName varchar(20), reserved integer default 0)"
    }

    override fun onCreate(db: SQLiteDatabase) {
        db.execSQL(CREATE_USERDATA1)
        db.execSQL("insert into tb_Games(gameId, gameName, gameTime, gameNote, userName, reserved) values('1', '和平精英', '11.18', '双排上分', 'wangjiu', 0)")
        db.execSQL("insert into tb_Games(gameId, gameName, gameTime, gameNote, userName, reserved) values('2', '原神', '11.19', '寻找代练', 'wangjiu', 0)")
        db.execSQL("insert into tb_Games(gameId, gameName, gameTime, gameNote, userName, reserved) values('3', '王者荣耀', '11.19', '组队开黑', 'wangjiu', 0)")
    }

    override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
        if (oldVersion < 2) {
            db.execSQL("ALTER TABLE tb_Games ADD COLUMN reserved integer default 0")
        }
    }
}